/**
 * @ClassName Code03_EvenTimesOddTimes
 * @Description: TODO
 * @Author: JCC
 * @CreateTime: 2023/12/4 21:43
 */
public class Code03_EvenTimesOddTimes {

    // 数组中只有一种数，出现奇数次
    public static void printOddTimesNum1(int[] array) {
        int eor = 0;
        for (int num : array) {
            eor ^= num;
        }
        System.out.println(eor);
    }

    public static void test1() {
        printOddTimesNum1(new int[]{1,1,-1,2,3,3,2,4,4});
    }

    // 00010    2   00010
    // 10010   -2   11110
    // 00111    7   00111
    // 10111   -7   11001
    // 数组中有两种数，出现奇数次，其余的出现了偶数次
    public static void printOddTimesNum2(int[] array) {
        int eor = 0;
        for (int num : array) {
            eor ^= num;
        }
        int rightestOne = eor & (-eor);
        int m = 0;
        int n = 0;
        for (int num : array) {
            if ((num & rightestOne) != 0) {
                m ^= num;
            } else {
                n ^= num;
            }
        }
        System.out.println("m=" + m);
        System.out.println("n=" + n);
    }

    public static void test2() {
        printOddTimesNum2(new int[]{-1,0,4,4,5,5,6,6,6,6,7,7});
    }

    public static void main(String[] args) {
        //test1();
        test2();
    }


}
